﻿<Window x:Class="DataBinding.DataContextSetFromAnotherControlSourceInCode"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DataContext Set From Another Control Source In Code" Height="290" Width="504">
    <Grid>
        <GroupBox Header="Select Customer" Margin="20,24,0,60" HorizontalAlignment="Left" Width="175" Padding="7">
            <ListBox ItemsSource="{Binding}" Name="lbCustomers">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=FirstName}" />
                            <TextBlock Text=" " />
                            <TextBlock Text="{Binding Path=LastName}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>
        <GroupBox Header="Customer Details" HorizontalAlignment="Right" Margin="0,24,34,60" Width="175">
            <StackPanel DataContext="{Binding ElementName=lbCustomers, Path=SelectedItem, Mode=TwoWay}">
                <Label Foreground="DarkGray">First Name</Label>
                <TextBox Text="{Binding Path=FirstName}" Margin="20,-5,11,7" />
                <Label Foreground="DarkGray">Last Name</Label>
                <TextBox Text="{Binding Path=LastName}" Margin="20,-5,11,7" />
                <Label Foreground="DarkGray">Birthday</Label>
                <TextBox Text="{Binding Path=Birthday, TargetNullValue='', StringFormat=d}" Margin="20,-5,11,7" />
            </StackPanel>
        </GroupBox>
    </Grid>
</Window>
